<template>
    <section>
        <el-col :span="24">
            <el-form inline>
                <el-form-item>
                    <el-input v-model="form.factory_name" placeholder="工厂名称" @keyup.enter.native="searchBtn" clearable size="small"
                              style="width: 150px"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input v-model.trim="form.supplier_id" placeholder="工厂编码" @keyup.enter.native="searchBtn" clearable size="small"
                              style="width: 100px"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input v-model="form.tag_number" placeholder="吊牌编码" @keyup.enter.native="searchBtn" clearable size="small"
                              style="width: 100px"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-select v-model="form.status" placeholder="全部" size="small" style="width: 100px" clearable>
                        <el-option label="启用" :value=0></el-option>
                        <el-option label="禁用" :value=1></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-select v-model="form.is_oms" placeholder="推送状态" size="small" style="width: 100px" clearable>
                        <el-option label="未推送" :value=0></el-option>
                        <el-option label="已推送" :value=1></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-select v-model="form.is_eqb" placeholder="E签宝状态" size="small" style="width: 120px" clearable>
                        <el-option label="未开通(快哉)" :value=10></el-option>
                        <el-option label="已开通(快哉)" :value=11></el-option>
                        <el-option label="未开通(有香)" :value=20></el-option>
                        <el-option label="已开通(有香)" :value=21></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" class="el-icon-search" @click="searchBtn" size="small"
                               :loading="btnLoading">查询
                    </el-button>
                    <el-button type="warning" class="el-icon-plus" @click="addBtn" size="small"
                               :loading="btnLoading" :disabled="!nodeActions.includes('add')">新建工厂
                    </el-button>
                </el-form-item>
            </el-form>
        </el-col>
        <el-col :span="24">
            <el-tabs type="border-card" v-model="tab">
                <el-tab-pane v-for="(item, index) in tabList" :key="index" :label="item.label" :name="item.type">
                    <el-table :data="data" style="width: 100%" :max-height="tableHeight" v-loading="loading" size="small">
                        <el-table-column label="工厂名称" prop="factory_name" width="250" show-overflow-tooltip></el-table-column>
                        <el-table-column label="简称" prop="factory_name_jiancheng" width="150" show-overflow-tooltip></el-table-column>
                        <el-table-column label="工厂编码" align="center" prop="supplier_id" show-overflow-tooltip width="120"></el-table-column>
                        <el-table-column label="吊牌编号" align="center" prop="tag_number"></el-table-column>
                        <el-table-column label="工厂类别" align="center" prop="group_name" width="80"></el-table-column>
                        <el-table-column label="合同类型" align="center" prop="is_advance" width="80">
                            <template slot-scope="{ row }">
                                <div :style="{ color: row.is_advance == 1 ? '#67C23A' : '#c0c4cc' }">
                                    {{ row.is_advance == 1 ? "有预付款" : "无预付款" }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column label="快哉-e签宝" align="center" prop="kz_sing_status_eqb">
                            <template slot-scope="{ row }">
                                <div :style="{ color: row.kz_sing_status_eqb == 1 ? '#67C23A' : '#c0c4cc' }">
                                    {{ row.kz_sing_status_eqb == 1 ? "已开通" : "未开通" }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column label="有香如故-e签宝" align="center" prop="kz_sing_status_eqb" width="120">
                            <template slot-scope="{ row }">
                                <div :style="{ color: row.yxrg_sing_status_eqb == 1 ? '#67C23A' : '#c0c4cc' }">
                                    {{ row.yxrg_sing_status_eqb == 1 ? "已开通" : "未开通" }}
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column label="是否推送(巨益、巨沃)" align="center" prop="is_oms" width="160">
                            <template slot-scope="{ row }">
                                <el-tag v-if="row.is_oms==1" type="success" size="mini">已推送</el-tag>
                                <el-tag v-else type="info" size="mini">未推送</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column label="是否启用" align="center" prop="status" width="80">
                            <template slot-scope="{ row }">
                                <el-tag v-if="row.status==0" type="success" size="mini">已启用</el-tag>
                                <el-tag v-else type="info" size="mini">未启用</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" align="center" fixed="right" width="170">
                            <template slot-scope="{ row }">
                                <el-button type="text" size="mini" class="el-icon-edit" @click="editBtn(row)" :disabled="!(row.status!=1&&nodeActions.includes('edit'))">编辑</el-button>
                                <el-button type="text" size="mini" @click="openBtn(row.id, 1)" v-if="row.status==0" :disabled="!nodeActions.includes('edit')" style="color: red">禁用</el-button>
                                <el-button type="text" size="mini" @click="openBtn(row.id, 0)" v-else :disabled="!nodeActions.includes('edit')" style="color: #67C23A">启用</el-button>
                                &nbsp;
                                <el-dropdown trigger="click" style="font-size: 12px;" @command="dropdownBtn($event, row)">
                                    <span style="cursor: pointer;color: #409EFF;">
                                        更多操作<i class="el-icon-arrow-down el-icon--right"></i>
                                    </span>
                                    <el-dropdown-menu slot="dropdown" v-loading="">
                                        <el-dropdown-item command="EQB_KZ" icon="el-icon-finished" :disabled="row.status==1||row.kz_sing_status_eqb==1||!nodeActions.includes('edit')">
                                            开通e签宝(快哉)
                                        </el-dropdown-item>
                                        <el-dropdown-item command="EQB_YX" icon="el-icon-finished" :disabled="row.status==1||row.yxrg_sing_status_eqb==1||!nodeActions.includes('edit')">
                                            开通e签宝(有香)
                                        </el-dropdown-item>
                                        <el-dropdown-item command="PUSH" icon="el-icon-position" :disabled="row.status==1||row.is_oms==1||!nodeActions.includes('edit')">
                                            推送(巨益、巨沃)
                                        </el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </template>
                        </el-table-column>
                    </el-table>
                    <!--翻页栏-->
                    <div style="margin-top: 4px;overflow: hidden;float: right;">
                        <Page :total="total" :current="page" :page-size="limit" show-total @on-change="pageChange"></Page>
                    </div>
                </el-tab-pane>
            </el-tabs>
        </el-col>

        <!--工厂信息-->
        <el-dialog title="工厂信息" :visible.sync="factoryVisible" width="1000px" :close-on-click-modal="false" top="2%">
            <el-form ref="infoForm" :model="factoryForm" :rules="rules" label-position="right" label-width="120px" inline>
                <el-row style="margin-top: 10px">
                    <svg t="1717659283335" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9445" width="20" height="20"><path d="M407.466667 477.866667h-277.333334C93.866667 477.866667 64 448 64 409.6v-277.333333c0-36.266667 29.866667-66.133333 66.133333-66.133334h277.333334c36.266667 0 66.133333 29.866667 66.133333 66.133334v277.333333c2.133333 38.4-27.733333 68.266667-66.133333 68.266667zM132.266667 108.8c-12.8 0-25.6 10.666667-25.6 25.6v277.333333c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333333c0-12.8-10.666667-25.6-25.6-25.6h-277.333333zM407.466667 960h-277.333334C93.866667 960 64 930.133333 64 893.866667v-277.333334c0-36.266667 29.866667-66.133333 66.133333-66.133333h277.333334c36.266667 0 66.133333 29.866667 66.133333 66.133333v277.333334c2.133333 36.266667-27.733333 66.133333-66.133333 66.133333zM132.266667 590.933333c-12.8 0-25.6 10.666667-25.6 25.6v277.333334c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333334c0-12.8-10.666667-25.6-25.6-25.6h-277.333333z m618.666666-110.933333c-17.066667 0-34.133333-6.4-46.933333-19.2L563.2 320c-12.8-12.8-19.2-29.866667-19.2-46.933333s6.4-34.133333 19.2-46.933334L704 83.2c12.8-12.8 29.866667-19.2 46.933333-19.2 17.066667 0 34.133333 6.4 46.933334 19.2l140.8 140.8c12.8 12.8 19.2 29.866667 19.2 46.933333 0 17.066667-6.4 34.133333-19.2 46.933334l-138.666667 142.933333c-12.8 12.8-29.866667 19.2-49.066667 19.2z m0-373.333333c-6.4 0-12.8 2.133333-17.066666 6.4l-140.8 140.8c-4.266667 4.266667-6.4 10.666667-6.4 17.066666 0 6.4 2.133333 12.8 6.4 17.066667l140.8 140.8c4.266667 4.266667 10.666667 6.4 17.066666 6.4 6.4 0 12.8-2.133333 17.066667-6.4l140.8-140.8c4.266667-4.266667 6.4-10.666667 6.4-17.066667 0-6.4-2.133333-12.8-6.4-17.066666L768 113.066667c-4.266667-4.266667-8.533333-6.4-17.066667-6.4z m138.666667 853.333333h-277.333333c-36.266667 0-66.133333-29.866667-66.133334-66.133333v-277.333334c0-36.266667 29.866667-66.133333 66.133334-66.133333h277.333333c36.266667 0 66.133333 29.866667 66.133333 66.133333v277.333334c2.133333 36.266667-27.733333 66.133333-66.133333 66.133333zM614.4 590.933333c-12.8 0-25.6 10.666667-25.6 25.6v277.333334c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333334c0-12.8-10.666667-25.6-25.6-25.6h-277.333333z" fill="#1E87EB" p-id="9446"></path></svg>
                    <span style="font-size: 18px;font-weight: bold;vertical-align: bottom;margin-left: 4px;">基本信息</span>
                </el-row>
                <el-form-item label="工厂名称" prop="factory_name">
                    <el-input v-model="factoryForm.factory_name" placeholder="请输入工厂名称" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="简称" prop="factory_name_jiancheng">
                    <el-input v-model="factoryForm.factory_name_jiancheng" placeholder="请输入简称" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="工厂编码">
                    <el-input v-model="factoryForm.supplier_id" placeholder="工厂编码（自动生成）" style="width: 180px" disabled size="small"></el-input>
                </el-form-item>
                <el-form-item label="工厂类别" prop="groups">
                    <el-select v-model="factoryForm.group" placeholder="请选择" style="width: 180px" size="small">
                        <el-option v-for="(item, index) in tabList" :key="index" :label="item.label" :value="item.type" v-if="item.type!='all'"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="合同类型" prop="is_advance">
                    <el-select v-model="factoryForm.is_advance" placeholder="请选择" style="width: 180px" size="small" disabled>
                        <el-option  label="无预付款" :value=0></el-option>
                        <el-option  label="有预付款" :value=1></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="吊牌编码">
                    <el-input v-model="factoryForm.tag_number" placeholder="请输入吊牌编码" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="拼音简称">
                    <el-input v-model="factoryForm.pinyin_name" placeholder="请输入拼音简称" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="Qc免检">
                    <el-radio-group v-model="factoryForm.is_free">
                        <el-radio :label=0>否</el-radio>
                        <el-radio :label=1>是</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-row style="margin-top: 10px">
                    <svg t="1717659283335" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9445" width="20" height="20"><path d="M407.466667 477.866667h-277.333334C93.866667 477.866667 64 448 64 409.6v-277.333333c0-36.266667 29.866667-66.133333 66.133333-66.133334h277.333334c36.266667 0 66.133333 29.866667 66.133333 66.133334v277.333333c2.133333 38.4-27.733333 68.266667-66.133333 68.266667zM132.266667 108.8c-12.8 0-25.6 10.666667-25.6 25.6v277.333333c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333333c0-12.8-10.666667-25.6-25.6-25.6h-277.333333zM407.466667 960h-277.333334C93.866667 960 64 930.133333 64 893.866667v-277.333334c0-36.266667 29.866667-66.133333 66.133333-66.133333h277.333334c36.266667 0 66.133333 29.866667 66.133333 66.133333v277.333334c2.133333 36.266667-27.733333 66.133333-66.133333 66.133333zM132.266667 590.933333c-12.8 0-25.6 10.666667-25.6 25.6v277.333334c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333334c0-12.8-10.666667-25.6-25.6-25.6h-277.333333z m618.666666-110.933333c-17.066667 0-34.133333-6.4-46.933333-19.2L563.2 320c-12.8-12.8-19.2-29.866667-19.2-46.933333s6.4-34.133333 19.2-46.933334L704 83.2c12.8-12.8 29.866667-19.2 46.933333-19.2 17.066667 0 34.133333 6.4 46.933334 19.2l140.8 140.8c12.8 12.8 19.2 29.866667 19.2 46.933333 0 17.066667-6.4 34.133333-19.2 46.933334l-138.666667 142.933333c-12.8 12.8-29.866667 19.2-49.066667 19.2z m0-373.333333c-6.4 0-12.8 2.133333-17.066666 6.4l-140.8 140.8c-4.266667 4.266667-6.4 10.666667-6.4 17.066666 0 6.4 2.133333 12.8 6.4 17.066667l140.8 140.8c4.266667 4.266667 10.666667 6.4 17.066666 6.4 6.4 0 12.8-2.133333 17.066667-6.4l140.8-140.8c4.266667-4.266667 6.4-10.666667 6.4-17.066667 0-6.4-2.133333-12.8-6.4-17.066666L768 113.066667c-4.266667-4.266667-8.533333-6.4-17.066667-6.4z m138.666667 853.333333h-277.333333c-36.266667 0-66.133333-29.866667-66.133334-66.133333v-277.333334c0-36.266667 29.866667-66.133333 66.133334-66.133333h277.333333c36.266667 0 66.133333 29.866667 66.133333 66.133333v277.333334c2.133333 36.266667-27.733333 66.133333-66.133333 66.133333zM614.4 590.933333c-12.8 0-25.6 10.666667-25.6 25.6v277.333334c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333334c0-12.8-10.666667-25.6-25.6-25.6h-277.333333z" fill="#1E87EB" p-id="9446"></path></svg>
                    <span style="font-size: 18px;font-weight: bold;vertical-align: bottom;margin-left: 4px;">合同/银行信息</span>
                </el-row>
                <el-form-item label="公司资质" class="myform-item">
                    <el-select v-model="factoryForm.company_qualification" placeholder="请选择" style="width: 180px" size="small">
                        <el-option label="小规模" value="小规模"></el-option>
                        <el-option label="一般纳税人" value="一般纳税人"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="公司抬头" class="myform-item">
                    <el-input v-model="factoryForm.company_head" placeholder="请输入公司抬头" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="开户行" class="myform-item">
                    <el-input v-model="factoryForm.bank_of_deposit" placeholder="请输入开户行" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="开户行号" class="myform-item">
                    <el-input v-model="factoryForm.opening_bank_no" placeholder="请输入开户行号" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="银行账户" class="myform-item">
                    <el-input v-model="factoryForm.bank_account" placeholder="请输入银行账户" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="开票税率(专票)" class="myform-item">
                    <el-input type="number" v-model="factoryForm.tax_rate" placeholder="请输入税率（单位 %）" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="法人(联系人)" class="myform-item" prop="legal_person">
                    <el-input v-model="factoryForm.legal_person" placeholder="请输入法定代表" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="联系电话" class="myform-item" prop="contact_phone">
                    <el-input v-model="factoryForm.contact_phone" placeholder="请输入联系电话" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="联系地址" class="myform-item" prop="contact_address">
                    <el-input v-model="factoryForm.contact_address" placeholder="请输入联系地址" style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="营业执照" class="myform-item">
                    <el-upload class="avatar-uploader" action="/api/tool/fileImport" :show-file-list="false"
                               :headers="uploadHeaders"
                               :data="uploadData"
                               :on-success="(res)=>uploadSuccessHandle(res)"
                               :before-upload="beforeUpload">
                        <img v-if="factoryForm.business_license" :src="factoryForm.business_license" height="180px"/>
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    </el-upload>
                </el-form-item>
                <el-row style="margin-top: 10px">
                    <svg t="1717659283335" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9445" width="20" height="20"><path d="M407.466667 477.866667h-277.333334C93.866667 477.866667 64 448 64 409.6v-277.333333c0-36.266667 29.866667-66.133333 66.133333-66.133334h277.333334c36.266667 0 66.133333 29.866667 66.133333 66.133334v277.333333c2.133333 38.4-27.733333 68.266667-66.133333 68.266667zM132.266667 108.8c-12.8 0-25.6 10.666667-25.6 25.6v277.333333c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333333c0-12.8-10.666667-25.6-25.6-25.6h-277.333333zM407.466667 960h-277.333334C93.866667 960 64 930.133333 64 893.866667v-277.333334c0-36.266667 29.866667-66.133333 66.133333-66.133333h277.333334c36.266667 0 66.133333 29.866667 66.133333 66.133333v277.333334c2.133333 36.266667-27.733333 66.133333-66.133333 66.133333zM132.266667 590.933333c-12.8 0-25.6 10.666667-25.6 25.6v277.333334c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333334c0-12.8-10.666667-25.6-25.6-25.6h-277.333333z m618.666666-110.933333c-17.066667 0-34.133333-6.4-46.933333-19.2L563.2 320c-12.8-12.8-19.2-29.866667-19.2-46.933333s6.4-34.133333 19.2-46.933334L704 83.2c12.8-12.8 29.866667-19.2 46.933333-19.2 17.066667 0 34.133333 6.4 46.933334 19.2l140.8 140.8c12.8 12.8 19.2 29.866667 19.2 46.933333 0 17.066667-6.4 34.133333-19.2 46.933334l-138.666667 142.933333c-12.8 12.8-29.866667 19.2-49.066667 19.2z m0-373.333333c-6.4 0-12.8 2.133333-17.066666 6.4l-140.8 140.8c-4.266667 4.266667-6.4 10.666667-6.4 17.066666 0 6.4 2.133333 12.8 6.4 17.066667l140.8 140.8c4.266667 4.266667 10.666667 6.4 17.066666 6.4 6.4 0 12.8-2.133333 17.066667-6.4l140.8-140.8c4.266667-4.266667 6.4-10.666667 6.4-17.066667 0-6.4-2.133333-12.8-6.4-17.066666L768 113.066667c-4.266667-4.266667-8.533333-6.4-17.066667-6.4z m138.666667 853.333333h-277.333333c-36.266667 0-66.133333-29.866667-66.133334-66.133333v-277.333334c0-36.266667 29.866667-66.133333 66.133334-66.133333h277.333333c36.266667 0 66.133333 29.866667 66.133333 66.133333v277.333334c2.133333 36.266667-27.733333 66.133333-66.133333 66.133333zM614.4 590.933333c-12.8 0-25.6 10.666667-25.6 25.6v277.333334c0 12.8 10.666667 25.6 25.6 25.6h277.333333c12.8 0 25.6-10.666667 25.6-25.6v-277.333334c0-12.8-10.666667-25.6-25.6-25.6h-277.333333z" fill="#1E87EB" p-id="9446"></path></svg>
                    <span style="font-size: 18px;font-weight: bold;vertical-align: bottom;margin-left: 4px;">E签宝信息</span>
                </el-row>
                <el-form-item label="企业证件号(税号)">
                    <el-input v-model="factoryForm.certificate_no" placeholder="请输入企业证件号（税号）" :disabled="factoryForm.kz_sing_status_eqb == 1"
                              style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="姓名">
                    <el-input v-model="factoryForm.eqb_user" placeholder="请输入姓名" :disabled="factoryForm.kz_sing_status_eqb == 1"
                              style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="手机号码">
                    <el-input type="number" v-model="factoryForm.eqb_phone" placeholder="请输入手机号码" :disabled="factoryForm.kz_sing_status_eqb == 1"
                              style="width: 180px" size="small"></el-input>
                </el-form-item>
                <el-form-item label="身份证号码">
                    <el-input v-model="factoryForm.eqb_card" placeholder="请输入身份证号码" :disabled="factoryForm.kz_sing_status_eqb == 1"
                              style="width: 180px" size="small"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer">
                <el-button type="primary" @click="saveBtn" :loading="btnLoading" size="small">保 存</el-button>
            </div>
        </el-dialog>
    </section>
</template>

<script>

import {factoryList, factoryOpen, factoryOpenEqb, factoryPush, factorySave} from "@/api/produce/factory";
import {getToken} from "@/libs/util";

export default {
    name: "produce_factory",
    data() {
        return {
            tableHeight: window.innerHeight - 270,
            selectIndex: 0,
            btnLoading: false,
            loading: false,
            page: 1,
            limit: 20,
            total: 0,
            data: [],
            user: {},
            nodeActions: [],

            form:{factory_name: "",supplier_id: "", tag_number: "",status: 0, is_oms: "",is_eqb: ""},
            tab: "all",
            tabList: [{label: "全部", type: "all"}, {label: "成衣厂", type: "1"}, {label: "绣花厂", type: "2"}, {label: "烫金厂", type: "5"},
                {label: "印花厂", type: "6"}, {label: "赠品供应商", type: "7"}, {label: "物料厂", type: "8"}],

            factoryVisible: false,
            factoryForm: {
                factory_name_jiancheng: "", // 工厂简称 factory_name_jiancheng
                factory_name: "", // 工厂名称 factory_name
                group: "1", // 工厂类型 1成衣厂 2绣花厂 5烫金厂6印花厂7赠品供应商8物料厂 groups
                is_advance: 0, // 1 需要预付 0 不需要预
                tag_number: "", // 吊牌编号 tag_number
                company_qualification: "", // 公司资质 company_qualification
                company_head: "", // 公司抬头 company_head
                bank_of_deposit: "", // 开户行 bank_of_deposit
                opening_bank_no: "", // 开户行号 opening_bank_no
                bank_account: "", // 银行账户 bank_account
                legal_person: "", //法定代表 legal_person
                contact_phone: "", //联系电话 contact_phone
                contact_address: "", //联系地址 contact_address
                tax_rate: "", // 税率 tax_rate
                business_license: "", // 图片 business_license
                pinyin_name: "", // 拼音简称
                certificate_no: "", //企业证件号（税号）
                eqb_user: "", //姓名
                eqb_phone: "", //手机号码
                eqb_card: "", // 身份证
                is_free: 0,
            },
            rules: {
                factory_name: [
                    { required: true, message: "请输入工厂名称", trigger: "blur" },
                ],
                factory_name_jiancheng: [
                    { required: true, message: "请输入工厂简称", trigger: "blur" },
                ],
                groups: [
                    { required: true, message: "请选择工厂类别", trigger: "blur" },
                ],
                is_advance: [
                    { required: true, message: "请选择合同类型", trigger: "blur" },
                ],
                company_qualification: [
                    { required: true, message: "请选择公司资质", trigger: "blur" },
                ],
                company_head: [
                    { required: true, message: "请输入公司抬头", trigger: "blur" },
                ],
                bank_of_deposit: [
                    { required: true, message: "请输入开户行", trigger: "blur" },
                ],
                opening_bank_no: [
                    { required: true, message: "请输入开户行号", trigger: "blur" },
                ],
                bank_account: [
                    { required: true, message: "请输入银行账户", trigger: "blur" },
                ],
                tax_rate: [
                    {
                        required: true,
                        message: "请输入专票税率（单位 %）",
                        trigger: "blur",
                    },
                ],
                legal_person: [
                    { required: true, message: "请输入法定代表", trigger: "blur" },
                ],
                contact_phone: [
                    { required: true, message: "请输入联系电话", trigger: "blur" },
                ],
                contact_address: [
                    { required: true, message: "请输入联系地址", trigger: "blur" },
                ],
                business_license: [
                    { required: true, message: "请上传图片", trigger: "blur" },
                ],
            },

            uploadHeaders: {},
            uploadData:{type: 'produce_factory', disk: 'image'},
        }
    },
    created() {
        this.user = this.$store.getters.user;
        this.nodeActions = this.user.node_actions[this.$route.meta.id] ? this.user.node_actions[this.$route.meta.id] : [];
    },
    watch:{
        tab(newVal, oldVal){
            this.searchBtn();
        },
    },
    methods: {
        //搜索按钮
        searchBtn() {
            this.page = 1;
            this.getData();
        },
        //翻页
        pageChange(page) {
            this.page = page;
            this.getData();
        },
        //获取数据
        getData() {
            let param = {
                page: this.page,
                limit: this.limit,
                tab: this.tab
            };
            param = Object.assign(this.form, param);
            this.loading = true;
            factoryList(param).then((res) => {
                this.loading = false;
                this.total = res.data.total;
                this.data = res.data.data;
            }).catch(() => {
                this.loading = false;
            });
        },
        //新增
        addBtn(){
            this.factoryForm = {
                factory_name_jiancheng: "",
                factory_name: "",
                group: "1",
                is_advance: 0,
                tag_number: "",
                company_qualification: "", // 公司资质
                company_head: "", // 公司抬头
                bank_of_deposit: "", // 开户行
                opening_bank_no: "", // 开户行号
                bank_account: "", // 银行账户
                legal_person: "", //法定代表
                contact_phone: "", //联系电话
                contact_address: "", //联系地址
                tax_rate: 0, // 税率
                business_license: "", // 图片
                pinyin_name: "",
                certificate_no: "", //企业证件号（税号）
                eqb_user: "", //姓名
                eqb_phone: "", //手机号码
                eqb_card: "", // 身份证
                is_free: 0,
            };
            this.factoryVisible = true;
        },
        //编辑
        editBtn(row){
            this.factoryForm = JSON.parse(JSON.stringify(row));
            this.factoryVisible = true;
        },
        //启用、禁用
        openBtn(id, status){
            this.$confirm(`【${status == 1 ? "禁用" : "启用"}】该工厂, 是否继续?`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                this.loading = true;
                factoryOpen({id: id, status: status}).then((res) =>{
                    this.loading = false;
                    if(res.code === 0){
                        this.$message.success(status == 1 ? "禁用成功" : "启用成功");
                        this.getData();
                    }else{
                        this.$message.error(res.msg);
                    }
                }).catch(()=>{
                    this.loading = false;
                })
            }).catch(() => {

            });
        },
        //更多操作
        dropdownBtn(command, row){
            switch (command){
                case "EQB_KZ":
                case "EQB_YX":
                    let msg = command == "EQB_KZ" ? "年年有余" : "有香如故";
                    let type = command == "EQB_KZ" ? "kz" : "yx";
                    this.$confirm(`确定开通E签宝-${msg}?`, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.loading = true;
                        let obj = {
                            supplier_id: row.supplier_id,
                            type: type
                        }
                        factoryOpenEqb(obj).then((res) =>{
                            this.loading = false;
                            if(res.code === 0){
                                this.$message.success(`${msg}, 开通成功`);
                                this.getData();
                            }else{
                                this.$message.error(`${msg}, 开通失败：`+res.msg);
                            }
                        }).catch(()=>{
                            this.loading = false;
                        })
                    }).catch(() => {
                    });
                    break;
                case "PUSH":
                    this.$confirm(`推送工厂到【巨益】、【巨沃】、【金蝶】?`, "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    }).then(() => {
                        this.loading = true;
                        factoryPush({supplier_id: row.supplier_id}).then((res) =>{
                            this.loading = false;
                            if(res.code === 0){
                                this.$message.success("推送成功");
                                this.getData();
                            }else{
                                this.$message.error(res.msg)
                            }
                        }).catch(()=>{
                            this.loading = false;
                        })
                    }).catch(() => {

                    });
                    break;
            }
        },
        uploadSuccessHandle(res){
            if(res.code === 0){
                this.$set(this.factoryForm, 'business_license', res.data);
            }else{
                this.$message.error(res.msg);
            }
        },
        beforeUpload(file) {
            if(!['image/jpg','image/jpeg','image/png'].includes(file.type)){
                this.$message.error('上传图片只能是 jpg、png 格式!');
                return false;
            }
            this.uploadHeaders.Authorization = 'Bearer '+ getToken();
            return true;
        },
        saveBtn(){
            if(!this.factoryForm.factory_name || !this.factoryForm.factory_name_jiancheng || !this.factoryForm.contact_address || !this.factoryForm.legal_person
                || !this.factoryForm.contact_phone){
                this.$message.warning("必填内容不能为空");return;
            }
            this.btnLoading = true;
            factorySave({data: JSON.stringify(this.factoryForm)}).then((res) =>{
                this.btnLoading = false;
                if(res.code === 0){
                    this.$message.success("保存成功");
                    this.factoryVisible = false;
                    this.getData();
                }else{
                    this.$message.error(res.msg);
                }
            }).catch(() => {
                this.btnLoading = false;
            });
        },
    },
    mounted() {
        this.searchBtn();
    }
}
</script>

<style scoped>
    /deep/ .el-dialog__body{
        padding: 0 20px;
    }

    /**************图片上传*************/
    .avatar-uploader /deep/ .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }
    .avatar-uploader /deep/ .el-upload:hover {
        border-color: #409EFF;
    }
    .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 8.5rem;
        height: 8.5rem;
        line-height: 8.5rem;
        text-align: center;
    }
    .avatar {
        width: 8.5rem;
        height: 8.5rem;
        display: block;
    }
    /**************图片上传*************/
</style>
